package com.jzo2o.orders.manager.service.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.foundations.ServeApi;
import com.jzo2o.api.foundations.dto.response.ServeAggregationResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author liuyp
 * @since 2024/12/20
 */
@Slf4j
@Component
public class ServeClient {

    @Resource
    private ServeApi serveApi;

    @SentinelResource(value = "findServeById", fallback = "findByIdFallback", blockHandler = "findByIdBlockHandler")
    public ServeAggregationResDTO findById(Long id){
        return serveApi.findById(id);
    }

    public ServeAggregationResDTO findByIdFallback(Long id, Throwable t){
        log.error("根据id查询服务异常，id={}", id, t);
        return null;
    }

    public ServeAggregationResDTO findByIdBlockHandler(Long id, BlockException e){
        log.error("根据id查询服务限流，id={}", id, e);
        return null;
    }
}
